package vn.easyforshopping.network;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import vn.easyforshopping.res.ResourceManager;
import vn.easyforshopping.utils.IActionListener;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;

public class GlobalServices {

	/**
	 * get 1 tam bitmap ve tu server.
	 * @param link
	 * @param onCompleted
	 */
	public static void getBitmap(final String link) {
		new Thread(new Runnable() {

			@Override
			public void run() {
				InputStream inputStream = null;
				try {
					URL url = new URL(link);
					HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();
					httpConnection.connect();
					inputStream = httpConnection.getInputStream();
					Bitmap b = BitmapFactory.decodeStream(inputStream);
					ResourceManager.getInstance().addBitMapIntoCache(link, b);
				} catch (Exception e) {
					Log.d("Global Services", e.getMessage());
				} finally {
					if (inputStream != null) {
						try {
							inputStream.close();
						} catch (IOException e) {
							Log.d("Global Services", e.getMessage());
						}
					}
				}
			}
		}).start();
	}
}
